﻿using Nova_Common;
using Nova_Common.Extend;
using Nova_DAL;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manage_ReplenShipList : System.Web.UI.Page
{
    Nova_DAL.DbHelper dbHelper = new DbHelper();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.hidden.Value != "" && this.hidden.Value != "undefined")
        {
            this.hidden.Value = "";
            gv_Bind();
        }
        if (!IsPostBack)
        {
            gv_Bind();
        }
    }

    protected void ibtn_Search_Click(object sender, ImageClickEventArgs e)
    {
        if(txt_StorageNo.Text.Trim().IsEmpty())
        {
            ShowBox.MessageBox(this.Page, "请填写入库单据号!");
            return;
        }
        gv_Bind();
    }

    public void gv_Bind()
    {
        string sqlStr = @"SELECT TAL.PID,TAL.Sec_Mat_ID,TAL.StockNo,TBM.Mat_Code,TBM.MAT_NAME, TBM.Unit_Base,
                        TAL.Num,TAL.Act_Num,TAL.S01,TAL.TS01,ISNULL(TCD.DETAIL_PID,0) DETAIL_PID  FROM dbo.TAddStorage_List TAL 
                        LEFT JOIN dbo.TBase_Material TBM ON TBM.MAT_CODE=TAL.MAT_CODE
                        LEFT JOIN dbo.TCommandsDetail TCD ON TAL.PID = TCD.DETAIL_PID
                        WHERE TAL.StockNo='" + txt_StorageNo.Text + "' ";
        DbCommand cmd = dbHelper.GetSqlStringCommond(sqlStr);
        gv.DataSource = dbHelper.ExecuteDataSet(cmd);
        gv.DataBind();
    }

    protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            LinkButton button = (LinkButton)e.Row.FindControl("lbtn_Replen");
            string[] sArray = button.CommandArgument.ToString().Split('|');
            string matCode = sArray[0].ToString();
            string secMatId = sArray[1].ToString();
            string num = sArray[2].ToString();
            string actNum = sArray[3].ToString();
            string pid = sArray[4].ToString();
            string str = string.Format("javascript: document.getElementById('{1}').value=window.showModalDialog('SearchTrayInfo.aspx?Ram=" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") +
                "&pid={0}&matCode={2}&secMatId={3}&num={4}', window, 'dialogWidth=900px;dialogHeight=530px;scroll:no;resizable:no;status:0;');document.URL=location.href;",
               pid, this.hidden.ClientID, matCode, secMatId,num);
            button.Attributes.Add("onclick", str);
            Label lab_DETAIL_PID = (Label)e.Row.FindControl("lab_DETAIL_PID");
            if (decimal.Parse(num) <= decimal.Parse(actNum))
            {
                button.Visible = false;
            }
            // ImageButton ibtnAutoOut = (ImageButton)e.Row.FindControl("ibtnAutoOut");
            if (lab_DETAIL_PID.Text != "0")  //Command_detail表中存在显示红色，表示正在处理
            {
                e.Row.ForeColor = Color.FromName("red");
                //ibtnAutoOut.Visible = false;   //订单明细正在处理的，自动操作按钮隐藏
            }

        }
    }
}